package com.capacitydorm.server.dao;

import com.capacitydorm.server.domain.Dorm;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface DormMapper extends Mapper<Dorm> {
    @Select("select  *  from   c_dorm where  id=#{id}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "number",column = "number"),
            @Result(property = "floorId",column = "floor_id"),
            @Result(property = "floor",one = @One(select = "com.capacitydorm.server.dao.FloorMapper.findById"), column = "floor_id"),
    })
    Dorm   findById(@Param("id") Integer   id);

    @Select("select  *  from   c_dorm where  number=#{number}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "number",column = "number"),
            @Result(property = "floorId",column = "floor_id"),
    })
    Dorm   findByNum(@Param("number") String  number);

    @Select("select  number  from   c_dorm ")
    List<String> selectAllNum();

    @Select("select * from c_dorm where floor_id = #{floor_id}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "number",column = "number"),
            @Result(property = "floorId",column = "floor_id"),
    })
    List<Dorm> findByFloorId(@Param("floor_id") Integer floor_id);
}
